/*
 * Licensed to the 南京汇海交通科技有限公司
 *
 * Copyright (c) 2025.
 * All rights reserved.
 *
 * 本软件属南京汇海交通科技有限公司所有，在未获得南京汇海交通科技有限公司正式授权情况下，任何企业和个人，不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
 */
package com.cje.basic.service.impl;

import com.chframework.boot.core.response.result.ApiResult;
import com.chframework.boot.core.response.status.ApiStatusEnum;
import com.chframework.common.exception.ServiceException;
import com.chframework.common.thread.wrapper.BenchmarksFuture;
import com.cje.basic.base.BaseService;
import com.cje.basic.service.TencentService;
import com.cje.service.pojo.dto.IpLocationDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

@Slf4j
@Service
@Controller
@RequiredArgsConstructor
@RequestMapping("/service/tencent")
public class TencentServiceImpl extends BaseService implements TencentService {

    @Override
    public ApiResult<IpLocationDTO> getIpLocation() {
        return BenchmarksFuture.supplyAsync(() -> locationService.getIpLocation(super.basicBizProperty.getTencentKey()))
                .thenApplyAsync(location -> ApiResult.<IpLocationDTO>build()
                        .setStatus(ApiStatusEnum.SUCCESS)
                        .setResult(location)
                ).exceptionally(throwable -> {
                    throw new ServiceException(throwable.getCause());
                }).join();
    }

}
